<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            margin: 100px auto;
            width: 700px;
            height: 560px;
            border: 1px solid black;

            /* background-color: red; */
        }

        .head {
            width: 100%;
            height: 60px;
            /* background-color: dodgerblue; */
        }


        h3 {
            float: left;
            line-height: 60px;
            margin-left: 20px;
        }

        ul {
            float: right;
            list-style: none;
            margin-left: 20px;
            margin-top: 20px;
            /* background-color: whitesmoke; */
        }

        ul li {
            display: inline-block;
            margin: 0 20px;
        }

        a {
            text-decoration: none;
            color: black;
        }

        .text {
            height: 400px;
            width: 700px;
            text-align: center;
            padding-top: 100px;
            display: none;
            /* background-color: yellow; */
        }

        .head .active {
            color: red;
            border-bottom: 2px solid red;
        }

        .content .active {
            display: block;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="head">
            <h3>每日特价</h3>
            <ul>
                <li><a href="#" class="active" data-id="0">精选</a></li>
                <li><a href="#" data-id="1">美食</a></li>
                <li><a href="#" data-id="2">百货</a></li>
                <li><a href="#" data-id="3">个护</a></li>
                <li><a href="#" data-id="4">预告</a></li>
            </ul>
        </div>
        <div class="content">
            <div class="text active"><img src="imges/01.jpg " alt="" width="400px"></div>
            <div class="text"><img src="imges/02.jpg" alt="" width="400px"></div>
            <div class="text"><img src="imges/03.jpg" alt="" width="400px" height="300px"></div>
            <div class="text"><img src="imges/04.jpg" alt="" width="400px"></div>
            <div class="text"><img src="imges/05.jpg" alt="" width="400px"></div>
        </div>
    </div>
    </div>

    <script>
        const ul = document.querySelector('ul')
        ul.addEventListener('click', function (e) {
            if (e.target.nodeName === 'A') {
                document.querySelector('.active').classList.remove('active');
                e.target.classList.add('active');
                const i = +e.target.dataset.id;
                document.querySelector('.content .active').classList.remove('active');
                document.querySelector(`.content .text:nth-child(${i + 1})`).classList.add('active')
            }
        })

    </script>
</body>

</html>